<template>
	<view class="reply-container">
		<view style="padding: 20rpx;">
			<view class="title"><text style="color: red;">*</text>完成描述</view>
			<textarea style="height: 320rpx;"  :maxlength="500" class="content" v-model="params['检查项'][0]['完成描述']" placeholder="请输入巡逻描述..." name="" id="" cols="30" rows="10"></textarea>
		</view>
		<view class="title" style="margin-left: 20rpx;"><text style="color: red;">*</text>完成附件</view>
		<view style="margin-left: 8rpx;">
			<uploader :max="10" @input='onchange'></uploader>
		</view>
		<button style="margin-bottom: 60rpx;" class="patrol-btn" @click="submit">提交</button>
	</view>
</template>

<script>
	import uploader from '@/components/my-components/image-uploader.vue'
	export default {
		data() {
			return {
				taskId: null,
				params: {
					检查项: [{
						任务记录id: null,
						检查项id: null,
						完成描述: '',
						附件: []
					}]
				}
			}
		},
		components: {
			uploader
		},
		onLoad(options) {
			this.taskId = +options.taskId
			this.params.检查项[0].检查项id = +options.id
			this.params.检查项[0].任务记录id = +options.recordId
		},
		methods: {
			onchange(e) {
				this.params.检查项[0].附件 = e
			},
			submit() {
				console.log(this.params)
				if(this.params['检查项'][0]['完成描述'].trim() == ''){
					uni.showToast({
						title: '请填写完成描述',
						icon: 'none'
					})
				}else if(!this.params['检查项'][0]['附件'].length){
					uni.showToast({
						title: '请上传完成附件',
						icon: 'none'
					})
				}else {
					uni.showLoading({mask: true})
					this.completeCheck()
				}
			},
			completeCheck() {
				uni.showLoading({mask: true})
				this.$http.post('taskSystem/task/itemRecord/submit', this.params).then(res => {
					// console.log(res)
					if (res.code === 10000) {
						uni.redirectTo({
							url: '/taskSystem/operateSuccess/operateSuccess?path=../qualityInspectDetail/qualityInspectDetail' + '&id=' + this.taskId
						})
						// uni.redirectTo({
						// 	url: '/ticketSystem/acceptSuccess/acceptSuccess?path=/taskSystem/list/list' + '&title=返回任务首页'
						// })
						
					}else if(res.code === 50001) {
						uni.showToast({
							title: '提交失败,任务还未开始',
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.reply-container {
		// padding: 20rpx;
		.title {
			margin-bottom: 20rpx;
		}
		.content {
			width: 710rpx;
			padding: 20rpx;
			border: 2rpx solid #ccc;
		}
		.patrol-btn {
			width: 568rpx;
			height: 80rpx;
			line-height: 80rpx;
			margin-top: 200rpx;
			background: linear-gradient(to right, #3350D9, #1152FC);
			// background-color: #1152FC;
			color: #fff;
		}
		.sign-item {
			margin-left: 20rpx;
			width: 220rpx;
			height: 220rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>